class_name Card
extends Control

@onready var card: Card = $"."
@onready var card_icon: TextureRect = $CardIcon
@onready var quality_color: ColorRect = $QualityColor
@onready var card_name: Label = $CardName
@onready var card_effect_description: RichTextLabel = $CardEffectDescription
@onready var card_description: Label = $CardDescription

var CardID: String = "card_01"
var card_data

func _ready() -> void:
	var cards_data = Game.load_json_file(Game.CARD_DATA_PATH)
	var _cards_data_keys = cards_data.keys()
	card_data = cards_data.get(CardID)
	initialize_card()

func initialize_card() -> void:
	#print(card_data)
	card_name.text = card_data.card_name
	card_effect_description.text = card_data.card_effect_description
	card_description.text = card_data.card_description
	card_icon.texture = load(card_data.card_icon)
	
	if card_data.card_quality == "normal":
		quality_color.color = "#ffffff"
	elif card_data.card_quality == "rare":
		quality_color.color = "#65ff4a"
	elif card_data.card_quality == "legend":
		quality_color.color = "#ffff00"

func _on_mouse_entered() -> void:
	card.scale = Vector2(1.05, 1.05)

func _on_mouse_exited() -> void:
	card.scale = Vector2(1.0, 1.0)

func _on_gui_input(event: InputEvent) -> void:
	if event.is_action_pressed("left_mouse"):
		#print(self)
		Game.inventory.add_card(card_data)
		if card_data.has("effect"):
			var effect = Effect.new()
			effect.execute(card_data.effect)
		Game.finish_card_choose()
